<style>
	
</style>
<template>
<div>
    <Card :bordered="false" dis-hover>
        <p slot="title">用户管理</p>
        <Row :gutter="20">
			<Col span="24">
				
				<div style="margin-top:10px;">

					<form action="http://localhost:3000/api/login/login?a=3" method="post" enctype="multipart/form-data">
					  <input type="text" name="username" value="admin">
					  <input type="text" name="password" value="star">
					  <button type="submit">submit</button>
					</form>
					<button @click="login">login</button>	

					<div class="ivu-table-wrapper" >
			            <div class="ivu-table ivu-table-with-fixed-top ">
			                <div class="ivu-table-body" >
								
			                    <table  class="table_border _table"   cellspacing="0" cellpadding="0" border="0" style="width: 100%;">
				                   
				                    <thead>
					                    <tr>
					                        <th class="" style="width:50px;">
					                            <div class="ivu-table-cell">
					                                <span>	序号</span>
					                            </div>
					                        </th>
					                        <th class="">
					                            <div class="ivu-table-cell">
					                                <span>用户名</span>
					                            </div>
					                        </th>
					                        <th class="" style="width:200px;">
					                            <div class="ivu-table-cell">
					                                <span>状态</span>
					                            </div>
					                        </th>
					                        <th class="" style="width:200px;">
					                            <div class="ivu-table-cell">
					                                <span>注册时间</span>
					                            </div>
					                        </th>
					                        <th class="" style="width:200px;">
					                            <div class="ivu-table-cell">
					                                <span>	操作</span>
					                            </div>
					                        </th>
					                    </tr>
				                    </thead>
				                    <tbody class="ivu-table-tbody">
					                    <tr class="ivu-table-row" v-for="(item,index) in data">
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <span>{{index+1}}</span>
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <span>{{item.name}}</span>
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <span>	{{item.state | decode('usertype')}}</span>
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                               {{item.time | formatDate('yyyy-MM-dd hh:mm:ss')}}
					                            </div>
					                        </td>
					                        <td class="">
					                            <div class="ivu-table-cell">
					                                <Button  size="small" type="error" 
					                                @click="deleteuser(item)">删除</Button>
					                                <Button  size="small" type="warning" 
					                                @click="updateuser(item)">修改</Button>
					                            </div>
					                        </td>
					                    </tr>
				                    </tbody>
			                    </table>
			                    <div class="body_empty" v-if="data.length==0 ">
			                    	暂无数据
			                    </div>
			                </div>
			            </div>
			            
			        </div>
		       	</div>
		       	<p style="margin-top:20px;">
					<Button type="primary" @click="adduser">添加</Button>
					<Page :total="page.total" :current="page.currentPage" placement="top" :page-size="page.pageSize"   @on-change="changePage" show-total style="float: right;"></Page>
				</p>
			</Col>
        </Row>
    </Card>
	<user-edit @refresh="getuser"></user-edit>
</div>	
</template>
<script>
import UserEdit from "../Module/useredit.vue";
export default {
	components:{UserEdit},
	data (){
		return {
			modal:false,value:'',title:'添加',addressPhone:'',
			rightobj:{},
			bankAccount:'',invoiceMaxAmount:'',
			colors:['yellow','blue'],texts:['正常','禁用'],
			data2:[],
			page:{total:0,currentPage:1,pageSize:10},
			data:[
				
			]
		}
	},mounted(){
		$('._table').resizableColumns({});
	},methods:{
		login(){
			// $.post('http://localhost:3000/api/login/login',{
			// 	username:'admin',password:'star'
			// }).then(res=>{
			// 	console.log(res);
			// 	return res
			// }).then(res=>{
			// 	// $.get('http://localhost:3000/api/login/user',{
					
			// 	// }).then(res=>{
			// 	// 	console.log(res);
			// 	// })
				

			
			// })

			$.ajax({

	              
               url: "http://localhost:3000/api/login/user",
               data:{username:'admin',password:'star'},
               dataType: 'jsonp',
		        type : 'get',
		        crossDomain: true,
		        contentType: "application/json", // POST时必须

		           success:function(res){
		           	console.log(res);

		     }
		    })
		},
		changePage (pageNum){
			this.page.currentPage = pageNum;
     		this.getuser();
		},add(){
			this.axios.post('/',{
				id:this.id,title:this.value,invoiceMaxAmount:this.invoiceMaxAmount,
				addressPhone:this.addressPhone,bankAccount:this.bankAccount
				}).then((res)=>{

			})
			this.modal=false;
			this.title='';
			this.$Message.success('添加成功!');
		},update(){
			this.axios.post('/company/update',
				{
					guid:this.id,name:this.value,
					bankAccount:this.bankAccount,addressPhone:this.addressPhone,
					invoiceMaxAmount:this.invoiceMaxAmount
				}).then((res)=>{
					//console.log(res);
					if(res.errorCode==0){
						this.modal=false;
						this.title='';
						this.$Message.success('修改成功!');
						this.getuser();
					}else{
						this.$Message.error(res.message);
					}
					
			})
			
		},deleteuser(item){
			this.$Modal.confirm({
                 title:'删除提示',
                 content: '<p>确定删除？</p>',
                 onOk:()=>{
                     this.axios.post('/login/remove/'+item._id,{}).then((res)=>{
                     	if(res.errorCode==0){
                     		this.$Message.info('删除成功');
                     		this.page.currentPage=1;
                        	this.getuser();
                     	}
                        
                    })
                }
            })
		},updateuser(item){
			this.$bus.emit('bus_useredit',item);
		},adduser(){
			
			this.$bus.emit('bus_useredit',{
				name:'',pwd:'',type:''
			})
		},getuser(){
			this.axios.post('/login/list',this.page).then((res)=>{
				console.log(res);
				if(res.errorCode==0){
					this.data=res.data.list;
					this.page.total=res.data.total;
					this.page.currentPage=res.data.pageNo  || 1;
				}
			})
		}
	},created(){
		this.getuser();
	},activated(){
		this.getuser();
	}
}
</script>